<template>
	<view class="live">
		<view v-if="list.length">
			<view class="live-item" v-for="(data,index) in list" :key="index" @click="goLive(data)">
				<image :src="data.feeds_img" mode="aspectFill"></image>
				<view class="name">{{data.name}}</view>
				<view class="status" :class="{ing: data.live_status==101,staring: data.live_status==102,end: data.live_status==103}">
					<view v-if="data.live_status==101" style="display: flex; align-items: center;">
						<view class="playing__bars">
							<view class="playing__bar playing__bar1"></view>
							<view class="playing__bar playing__bar2"></view>
							<view class="playing__bar playing__bar3"></view>
						</view>
						直播中
					</view>
					<view v-if="data.live_status==102" style="display: flex; align-items: center;">
						<view class="label">即将开播:</view>
						<view class="count-down" style="margin-left: 20rpx;">
							<u-count-down 
								:timestamp="data.start_time - new Date().getTime() / 1000" 
								separator="zh" 
								font-size="24" 
								height="36"
								separator-size="24"
								separator-color="#FFF"
								bg-color="#FFF"
								color="#FF811B">
							</u-count-down>
						</view>
					</view>
					<view v-if="data.live_status==103">已结束</view>
				</view>
			</view>
		</view>
		<pt-nothing fixed icon="https://jiajudashi.oss-cn-shenzhen.aliyuncs.com/images/shop/icons/nothing.png?v=1" text="暂无直播间" v-else></pt-nothing>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				list: [],
				Refresh: false
			};
		},
		onPullDownRefresh() {
			this.Refresh = true
			this.init()
		},
		onLoad() {
			this.init()
		},
		methods: {
			async init(){
				const { datas } = await this.$u.api.LiveList({start: 0,limit: 100})
				this.list = datas.room_info
				if(this.Refresh){
					this.Refresh = false
					uni.showToast({
						icon: 'none',
						title: '刷新成功'
					})
					uni.stopPullDownRefresh()
				}
			},
			goLive(data){
				uni.navigateTo({
					url: `plugin-private://wx2b03c6e691cd7370/pages/live-player-plugin?room_id=${data.roomid}`
				})
			}
		}
	}
</script>

<style lang="scss">
	page{
		background-color: #F8F8F8;
	}
</style>
<style lang="scss" scoped>
	.live{
		padding: 30rpx;
		.live-item{
			margin-top: 30rpx;
			border-radius: 16rpx;
			background-color: #FFF;
			position: relative;
			&:first-child{
				margin-top: 0;
			}
			image{
				width: 100%;
				height: 340rpx;
			}
			.name{
				padding: 30rpx;
				font-size: 32rpx;
				font-weight: bold;
			}
			.status{
				position: absolute;
				height: 52rpx;
				line-height: 52rpx;
				border-radius: 16rpx 0px 16rpx 0px;
				padding: 0 20rpx;
				top: -8rpx;
				left: -8rpx;
				font-size: 28rpx;
				&::before{
					position: absolute;
					content: '';
					width: 0;
					height: 0;
					border-top: solid 10rpx #999;
					border-left: solid 10rpx transparent;
					bottom: -10rpx;
					left: 0;
				}
				&.ing{
					background: linear-gradient(-51deg, #FF3737, #FF0707);
					color: #FFF;
					&::before{
						border-top: solid 10rpx #D40000;
					}
				}
				&.staring{
					background-color: #FF811B;
					color: #FFF;
					&::before{
						border-top: solid 10rpx #E36B00;
					}
				}
				&.end{
					background-color: #B3B3B3;
					color: #FFF;
					&::before{
						border-top: solid 10rpx #999;
					}
				}
			}
		}
	}
	
	.playing__bars{
		width: 32rpx;
		height: 32rpx;
		background-color: #FFF;
		border-radius: 50%;
		display: flex;
		align-items: center;
		justify-content: center;
		margin-right: 10rpx;
	}
	
	.playing__bar {
	  background: #FF374F;
	  width: 4rpx;
	  height: 18rpx;
		animation: up-and-down 1.3s ease infinite alternate;
		border-radius: 4rpx;
		margin: 2rpx;
	}
	
	.playing__bar1 {
	  height: 60%;
	}
	
	.playing__bar2 {
	  height: 30%;
	  animation-delay: -2.4s;
	}
	
	.playing__bar3 {
	  height: 75%;
		animation-delay: -3.7s;
	}
	
	@keyframes up-and-down {
	  10% {
	    height: 6rpx;
	  }
	  30% {
	    height: 18rpx;
	  }
	  60% {
	    height: 9rpx;
	  }
	  80% {
	    height: 13.5rpx;
	  }
	  100% {
	    height: 3.6rpx;
	  }
	}
</style>
